﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using fingerWinForm.Excel;
using fingerWinForm.Utilities;


namespace fingerWinForm
{
    public partial class addNewPatientWindow : Form
    {
        FileMgr excelManeger;

        public addNewPatientWindow(FileMgr futherExcelManeger)
        {
            InitializeComponent();
            excelManeger = futherExcelManeger;
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            excelManeger.closeFileMgr();
            excelManeger = null; //free this manager
            Close();
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            PatientDetails patientDetails = new PatientDetails();
            String message = "";
            if (!CheckInput.isNumber(idTextBox.Text))
            {
                message = "ID must contains only numbers\n";
            }
            if (!CheckInput.isLetters(firstNameTextBox.Text))
            {
                message += "First Name must contains only letters\n";
            }
            if (!CheckInput.isLetters(lastNameTextBox.Text))
            {
                message += "Last Name must contains only letters\n";
            }
            if (CheckInput.isEmpty(genderComboBox.Text))
            {
                message += "Gender was not choosen\n";
            }
            if (!CheckInput.isNumber(phoneTextBox.Text))
            {
                message += "Phone Number must contains only numbers\n";
            }  
            if (message != "")
            {
                MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            patientDetails.id = idTextBox.Text;
            patientDetails.firstName = firstNameTextBox.Text;
            patientDetails.lastName = lastNameTextBox.Text;
            if (genderComboBox.Text == "Male")
            {
                patientDetails.gender = "Male";
            }
            else
            {
                patientDetails.gender = "Female";
            }
            
            patientDetails.birthDate = birthDatePicker.Text;
            patientDetails.phoneNumber = phoneTextBox.Text;
            excelManeger.addNewPatientDetails(patientDetails);

            //if(this!=null)
            Close();

        }

        private void addNewPatientWindow_Load(object sender, EventArgs e)
        {

        }

        
    }
}
